package com.fenqiyong.www.action;

import android.content.Context;

import com.orhanobut.logger.Logger;
import com.tougc.bean.beans.ScondBean;

import java.util.HashMap;

import javax.inject.Inject;

import io.reactivex.Observable;
import ren.nearby.http.request.BaseObserver;
import ren.nearby.http.request.HttpApi;
import ren.nearby.http.request.SchedulersCompat;
import ren.nearby.http.utils.util.ReqMessage;
import ren.nearby.http.utils.util.RxDisposble;
import ren.nearby.http.view.progress.DialogRequest;

/**
 * Created by Administrator on 2018/5/18 0018.
 */

public class FragmentScondCarPresent implements FragmentScondCarContract.Action {
    FragmentScondCarContract.View mView;  // 需要抽象出来
    @Inject
    HttpApi mApi;
    @Inject
    Context context;

    @Inject
    FragmentScondCarPresent() {
    }

    @Override
    public void takeView(FragmentScondCarContract.View view) {
        mView = view;
    }

    @Override
    public void dropView() {
        mView = null;
        RxDisposble.getInstance().unSubscribe();
    }

    @Override
    public void R0021() {

        try {
            HashMap<String, Object> map = new HashMap<>();

            final String message = ReqMessage.getInstance().message(map, context);
            Logger.e("message = " + message);
//                Observable ob = mApi.testRent(message);
            Observable ob = mApi.R0021(message);
            BaseObserver observer = new BaseObserver<ScondBean>(mView.getActivity()) {


                @Override
                public void onNext(ScondBean bean) {
                    Logger.e("onNext = ");
                    mView.setBanner(bean.getImageList());

                }
            };
            ob.compose(SchedulersCompat.IO_TRANSFORMER)//处理线程
//                    .compose(RxResultHelper.handleResult())
                    .compose(SchedulersCompat.applyProgress(mView.getActivity(), DialogRequest.TAG_REQUEST))
                    .subscribe(observer);


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void R0022(int currPage, int pageSize) {

        try {
            HashMap<String, Object> map = new HashMap<>();
            map.put("currPage", currPage);
            map.put("pageSize", pageSize);
            final String message = ReqMessage.getInstance().message(map, context);
            Logger.e("message = " + message);
//                Observable ob = mApi.testRent(message);
            Observable ob = mApi.R0022(message);
            BaseObserver observer = new BaseObserver<ScondBean>(mView.getActivity()) {


                @Override
                public void onNext(ScondBean bean) {
                    Logger.e("onNext = ");
                    mView.setScondBean(bean.getPage());

                }
            };
            ob.compose(SchedulersCompat.IO_TRANSFORMER)//处理线程
//                    .compose(RxResultHelper.handleResult())
                    .compose(SchedulersCompat.applyProgress(mView.getActivity(), DialogRequest.TAG_REQUEST))
                    .subscribe(observer);


        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}


